﻿package net.wangit.dev.group;

import net.wangit.jdbc.DB;
import net.wangit.jdbc.Type;
import net.wangit.util.Checker;

public class GroupReferenceUtil {

	private static final String SQL_TABLE = "update TABLE set gid=? where gid=?";
	private static final String SQL_UNIT = "update UNIT set gid=? where gid=?";
	private static final String SQL_ENUMERATION = "update ENUMCONFIG set gid=? where gid=?";
	private static final String SQL_TREE = "update TREECONFIG set gid=? where gid=?";
	private static final String SQL_CHART = "update CHART set gid=? where gid=?";
	private static final String SQL_DATA_PRIVILE = "update DPCONFIG set gid=? where gid=?";
	private static final String SQL_INCREMENTOR = "update INCREMENTOR set gid=? where gid=?";

	public GroupReferenceUtil() {
	}

	public static void update(DB db, String domain, int groupType,
			String oldGroupId, String newGroupId) throws Exception {
		if (Checker.isEmpty(oldGroupId) || oldGroupId.equals(newGroupId))
			return;
		String values[] = { newGroupId, oldGroupId };
		int types[] = { Type.VARCHAR, Type.VARCHAR };
		switch (groupType) {
		case 1:
			db.execute(GroupReferenceUtil.SQL_TABLE, values, types);
			break;

		case 2:
			db.execute(GroupReferenceUtil.SQL_UNIT, values, types);
			break;

		case 3:
			db.execute(GroupReferenceUtil.SQL_ENUMERATION, values, types);
			break;

		case 4:
			db.execute(GroupReferenceUtil.SQL_TREE, values, types);
			break;

		case 5:
			db.execute(GroupReferenceUtil.SQL_CHART, values, types);
			break;

		case 6:
			db.execute(GroupReferenceUtil.SQL_DATA_PRIVILE, values, types);
			break;

		case 7:
			db.execute(GroupReferenceUtil.SQL_INCREMENTOR, values, types);
			break;
		}
	}
}
